@import '../../styles/common';

$min-height: control-height();
$vertical-padding: ($min-height - line-height(body) - rem(2px)) / 2;
$difference-between-touch-area-and-backdrop: control-height() -
  control-slim-height();

// This is the adjustment needed to get the icon to appear flush with other
// content around it.
$plain-horizontal-adjustment: spacing(tight);

$stacking-order: (
  item: 10,
  focused: 20,
);

.Pagination {
  display: inline-flex;

  &:not(.plain) {
    @include page-content-when-fully-condensed {
      display: flex;
      width: 100%;

      .Button {
        flex: 1 0 auto;
      }
    }
  }
}

.plain {
  .Button {
    position: relative;
    margin-top: -0.5 * $difference-between-touch-area-and-backdrop;
    margin-bottom: -0.5 * $difference-between-touch-area-and-backdrop;
    padding-top: 0.5 * ($min-height - line-height(body));
    padding-bottom: 0.5 * ($min-height - line-height(body));
    background: transparent;
    border: none;
    cursor: pointer;
    appearance: none;
    box-shadow: none;

    &:hover,
    &:active {
      @include recolor-icon(color('ink'));
      background: transparent;
      border: none;
      box-shadow: none;
    }

    &:focus {
      border: none;
      box-shadow: none;

      // stylelint-disable-next-line selector-max-specificity
      &::after {
        background: plain-button-background();
      }
    }

    &:disabled {
      @include recolor-icon(color('sky', 'dark'));
      background: transparent;
      border: none;
      box-shadow: none;
    }

    &::after {
      content: '';
      position: absolute;
      top: 0.5 * $difference-between-touch-area-and-backdrop;
      right: 0;
      left: 0;
      display: block;
      height: control-slim-height();
      border-radius: border-radius();
      will-change: background;
      transition-property: background;
      transition-duration: duration();
      transition-timing-function: easing();
    }
  }

  .PreviousButton {
    margin-left: -1 * $plain-horizontal-adjustment;
  }

  .NextButton {
    margin-right: -1 * $plain-horizontal-adjustment;
    margin-left: rem(2px);
  }
}

.Button {
  @include recolor-icon(color('ink', 'lighter'));
  position: relative;
  z-index: z-index(item, $stacking-order);
  display: inline-block;
  min-width: $min-height;
  margin: 0;
  padding: $vertical-padding spacing(tight);
  background: linear-gradient(
    to bottom,
    color('white'),
    color('sky', 'lighter')
  );
  border: border(dark);
  border-radius: border-radius();
  line-height: 1;
  color: color('ink');
  text-align: center;
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  transition-property: color, background, border, box-shadow;
  transition-duration: duration();
  transition-timing-function: easing();

  &:hover {
    background: linear-gradient(
      to bottom,
      color('sky', 'lighter'),
      color('sky', 'light')
    );
    border-color: color('sky', 'dark');
  }

  &:focus {
    z-index: z-index(focused, $stacking-order);
    border-color: color('indigo');
    outline: 0;
    box-shadow: 0 0 0 1px color('indigo');
  }

  &:active {
    // Same color gradient is necessary for background transitions
    background: linear-gradient(
      to bottom,
      color('sky', 'light'),
      color('sky', 'light')
    );
    border-color: color('sky', 'dark');
    box-shadow: 0 0 0 0 transparent,
      inset 0 1px 1px 0 rgba(color('ink', 'lighter'), 0.1),
      inset 0 1px 4px 0 rgba(color('ink', 'lighter'), 0.2);
  }

  &:disabled {
    @include recolor-icon(color('ink', 'lightest'));
    background: color('sky', 'light');
    color: color('ink', 'lightest');
    cursor: default;
    box-shadow: none;
  }
}

.PreviousButton {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.NextButton {
  margin-left: -1px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
